import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image, Text, ScrollView } from "@tarojs/components-rn";
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, pageSize, subtime, typeOfJobObj } from "../../utils/common";
import collectionStyleSheet from "./collection_styles";
var _styleSheet = collectionStyleSheet;

function _getClassName() {
  var className = [];
  var args = arguments[0];
  var type = Object.prototype.toString.call(args).slice(8, -1).toLowerCase();

  if (type === 'string') {
    args = args.trim();
    args && className.push(args);
  } else if (type === 'array') {
    args.forEach(function (cls) {
      cls = _getClassName(cls).trim();
      cls && className.push(cls);
    });
  } else if (type === 'object') {
    for (var k in args) {
      k = k.trim();

      if (k && args.hasOwnProperty(k) && args[k]) {
        className.push(k);
      }
    }
  }

  return className.join(' ').trim();
}

function _getStyle(classNameExpression) {
  var className = _getClassName(classNameExpression);

  var classNameArr = className.split(/\s+/);
  var style = [];

  if (classNameArr.length === 1) {
    style.push(_styleSheet[classNameArr[0].trim()]);
  } else {
    classNameArr.forEach(function (cls) {
      style.push(_styleSheet[cls.trim()]);
    });
  }

  return style;
}

let Personnel = class Personnel extends Component {
  constructor(props) {
    super(props);
    this.state = {
      currentNavId: 1,
      pageIndex: 1,
      pageSize: pageSize,
      items: [],
      totalCount: 0,
      navArr: [{ id: 1, name: '动态' }, { id: 2, name: '人才' }, { id: 3, name: '招聘' }, { id: 4, name: '课程' }],
      dynamic: [],
      personnel: [],
      recruit: [],
      course: []
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '我的收藏' });
    this.getUserFavorites();
  }
  getUserFavorites() {
    let { userStore } = this.props.stores;
    let { pageIndex, pageSize } = this.state;
    userStore.getUserFavorites({
      pageIndex,
      pageSize,
      callback: res => {
        console.log(res);
        this.setState({
          dynamic: res.dynamic,
          personnel: res.personnel,
          recruit: res.recruit,
          course: res.course
        });
      }
    });
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  changeNavId(id = null) {
    this.setState({
      currentNavId: id
    });
  }
  render() {
    let { currentNavId, navArr, dynamic, personnel, recruit, course } = this.state;
    let tpl = null;
    if (currentNavId === 1) {
      tpl = <View style={_styleSheet["list-wrap"]}>
          {dynamic.length > 0 && dynamic.map(item => {
          if (item) {
            return <View onClick={this.handelRouter.bind(this, `/pages/dynamic/detail?id=${item.id}&isCollection=1`)} style={_styleSheet["item"]}>
                  <View style={_styleSheet["l"]}>
                    <Text style={_styleSheet["title"]}>{item.title}</Text>
                    <Text style={_styleSheet["date"]}>{subtime(item.creationTime)}</Text>
                  </View>
                  <Image src={item.logo} style={_styleSheet["img"]} />
                </View>;
          }
        })}
          {dynamic.length <= 0 && <View style={_styleSheet["page-none-info"]}>你还没有收藏的动态信息哦~</View>}
        </View>;
    } else if (currentNavId === 2) {
      tpl = <View style={_styleSheet["list-06"]}>
          {personnel.length > 0 && personnel.map(item => {
          return <View style={_styleSheet["list-06-item"]}>
                <View style={_styleSheet["item-title"]}>
                  <View style={_styleSheet["title"]}>
                    {item.positionName}
                    <Text style={_styleSheet["label"]}>{typeOfJobObj[item.typeOfJob]}</Text>
                  </View>
                </View>
                <View style={_styleSheet["item-info"]}>
                  <View style={_styleSheet["info"]}>
                    <Text style={_styleSheet["i"]}>{item.education}</Text>
                    
                    <Text style={_styleSheet["i"]}>{item.workYears}年</Text>
                  </View>
                  <View onClick={this.handelRouter.bind(this, `/pages/newest/personnel_detail?id=${item.id}&isCollection=1`)} style={_styleSheet["btn-view"]}>
                    查看
                  </View>
                </View>
              </View>;
        })}
          {personnel.length <= 0 && <View style={_styleSheet["page-none-info"]}>你还没有收藏的人才信息哦~</View>}
        </View>;
    } else if (currentNavId === 3) {
      tpl = <View style={_styleSheet["list-06"]}>
          {recruit.length > 0 && recruit.map(item => {
          return <View style={_styleSheet["list-06-item"]}>
                <View style={_styleSheet["item-title"]}>
                  <View style={_styleSheet["title"]}>
                    {item.positionName}
                    <Text style={_styleSheet["label"]}>{item.jobNature}</Text>
                  </View>
                  <View style={_styleSheet["address"]}>{item.address}</View>
                </View>
                <View style={_styleSheet["item-info"]}>
                  <View style={_styleSheet["info"]}>
                    <Text style={[_styleSheet["op"], _styleSheet["i"]]}>{item.monthlyPay}</Text>
                    <Text style={_styleSheet["i"]}>{item.education}</Text>
                    <Text style={_styleSheet["i"]}>{item.recruitment}人</Text>
                    <Text style={_styleSheet["i"]}>{item.technicalTitle}</Text>
                  </View>
                  <View onClick={this.handelRouter.bind(this, `/pages/newest/position_detail?id=${item.id}&isCollection=1`)} style={_styleSheet["btn-view"]}>
                    查看
                  </View>
                </View>
              </View>;
        })}
          {recruit.length <= 0 && <View style={_styleSheet["page-none-info"]}>你还没有收藏的招聘信息哦~</View>}
        </View>;
    } else if (currentNavId === 4) {
      tpl = <View style={_styleSheet["list-08"]}>
          {course.length > 0 && course.map(item => {
          return <View key={item.id} onClick={this.handelRouter.bind(this, `/pages/business_school/detail?id=${item.id}&isCollection=1`)} style={_styleSheet["list-08-item"]}>
                <Image src={item.courseLogoImg} style={_styleSheet["item-img"]} />
                <View style={_styleSheet["info"]}>
                  <View style={_styleSheet["title"]}>
                    {item.courseName}
                  </View>
                  <View style={_styleSheet["old-price"]}>￥{item.coursePrice}</View>
                  <View style={_styleSheet["price-wrap"]}>
                    <View style={_styleSheet["price"]}>VIP会员 ￥
                      <Text style={_styleSheet["big"]}>{item.vipCourserPrice}</Text>
                    </View>
                    <View style={_styleSheet["num"]}>128学过</View>
                  </View>
                </View>
              </View>;
        })}
          {course <= 0 && <View style={_styleSheet["page-none-info"]}>你还没有收藏的课程哦~</View>}
        </View>;
    }
    let commonTpl = <View style={[_styleSheet["newest-index"], _styleSheet["collection-index"]]}>
      <ScrollView scrollX={true} style={_styleSheet["scroll-view-nav"]}>
        {navArr.map(item => {
          return <View onClick={this.changeNavId.bind(this, item.id)} style={_getStyle(item.id === currentNavId ? 'scroll-item scroll-item-on' : 'scroll-item')}><Text style={_styleSheet["line"]} />{item.name}</View>;
        })}
      </ScrollView>
      <View style={_styleSheet["interval"]} />

      {tpl}
    </View>;
    return commonTpl;
  }
};
Personnel = tslib_1.__decorate([inject("stores"), observer], Personnel);
export default Personnel;